package com.yanqu.road.logic.redis;

import com.yanqu.road.utils.string.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class RedisServerOnlineCount {

    private static Logger logger = LogManager.getLogger(RedisServerOnlineCount.class.getName());

    /**
     * 设置区服在线数量
     * @param serverId
     * @param value
     */
    public static void setOnlineCount(long serverId, long value){
        RedisManger.getRedisUtil().setString(RedisKeyDefineHelper.getServerOnlineCountKey(serverId), value+"");
    }

    /**
     * 获取区服在线数量
     * @param serverId
     * @return
     */
    public static long getOnlineCount(long serverId){
        String onlineCount = RedisManger.getRedisUtil().get(RedisKeyDefineHelper.getServerOnlineCountKey(serverId));
        if(!StringUtils.isNullOrEmpty(onlineCount)){
            return Long.parseLong(onlineCount);
        }
        return 0;
    }
}
